﻿#ifdef UTIL_PLATFORM_LINUX
#include "lang/Runtime.h"
#include "sys/sysinfo.h"
#include "unistd.h"

namespace yzrilyzr_lang{
	int32_t Runtime::availableProcessors(){
		return (int32_t)sysconf(_SC_NPROCESSORS_ONLN);
	}
	int64_t Runtime::totalMemory(){
		struct sysinfo info;
		if(sysinfo(&info) == 0){
			return info.totalram * info.mem_unit;
		}
		return -1;
	}

	int64_t Runtime::freeMemory(){
		struct sysinfo info;
		if(sysinfo(&info) == 0){
			return info.freeram * info.mem_unit;
		}
		return -1;
	}

	int64_t Runtime::maxMemory(){
		// 在 Linux 中，最大内存通常是总物理内存
		return totalMemory();
	}
}
#endif